/**
 * 系统参数编辑、新增
 *
 */
define(["app", "js/services/MessageBox", "js/services/MuseService"], function (app) {

    var deps = ["$scope", "$state", "$modal", "$stateParams", "MessageBox", "MuseService"];

    function controller ($scope, $state, $modal, $stateParams, MessageBox, MuseService) {
        //获取参数
        var id = $stateParams.id || '';

        $scope.isCreated = false;
        if (isEmpty(id)) {
            $scope.isCreated = true;
        }

        //获取数据
        $scope.getDetail = function () {
            MuseService.get(baseServices_restfulUrl + "sysParam/load.json?id=" + id).success(
                function (data, status, headers, config) {
                    if (data.state == 0) {
                        $scope.sysParam = data.data;
                    } else {
                        MessageBox.error('获取数据失败:' + data.message);
                    }
                })
            .error(function () {
                MessageBox.error('服务器正在开小差zZZ,获取不到数据');
            });
        };
        if (id) {
            $scope.getDetail();
        }

        //保存
        $scope.saveObj = function () {
            MuseService.postObj(baseServices_restfulUrl + "sysParam/save.json", $scope.sysParam).success(
                function (data, status, headers, config) {
                    if (data.state == 0) {
                        $scope.result = data.data;
                        MessageBox.notify('保存成功!');
                        $state.go('sysParamList');
                    } else {
                        MessageBox.error('保存失败：' + data.message);
                    }
                })
            .error(function () {
                MessageBox.error('保存失败:服务器正在开小差zZZ');
            });
        };

        // 取消，返回
        $scope.close = function () {
            //$state.go("sysParamList");
            history.back();
        };
    }

    controller.$inject = deps;
    app.lazy.controller("SysParamEditController", controller);
});
